import './ft1.dart' show ft1;
import './pd.dart' show pd;

enum EnvCode {
  ft1,
  pd,
}

class Env {
  static Env? _instance;
  //当前环境
  static EnvCode? envCode;
  //CA灰度标识
  static String canaryHeader = 'Canary-Ver-20240304';
  static Env? getInstance() {
    if (Env._instance == null) {
      Env.init(EnvCode.ft1);
    }
    return Env._instance;
  }

  static void init(EnvCode code) {
    envCode = code;
    Map<String, dynamic> config = ft1;
    if (code == EnvCode.ft1) {
      config = ft1;
    } else {
      config = pd;
    }
    Env._instance = Env.fromJson(config);
  }

  final List<String> imageProcessOssBucketDomains;
  final String baseUrl;
  final String rcAppkey;
  final String gaoDeIoSAppKey;
  final String gaoDeAndroidAppKey, versionEnvDesc;
  final String csjAndroidAppId, csjIosAppId, csjAndroidCodeId, csjIosCodeId;
 
  
  

  Env(
    this.gaoDeIoSAppKey,
    this.gaoDeAndroidAppKey,
    this.rcAppkey, {
    required this.versionEnvDesc,
    required this.imageProcessOssBucketDomains,
    required this.baseUrl,
    required this.csjAndroidAppId,
    required this.csjIosAppId,
    required this.csjAndroidCodeId,
    required this.csjIosCodeId,
  });

  factory Env.fromJson(Map<String, dynamic> json) {
    return Env(
      json['GaoDeIoSAppKey'],
      json['GaoDeAndroidAppKey'],
      json['RCAppkey'],
      imageProcessOssBucketDomains: json['imageProcessOssBucketDomains'],
      baseUrl: json['baseUrl'] ?? "",
      csjAndroidAppId: json['csjAndroidAppId'] ?? "",
      csjIosAppId: json['csjIosAppId'] ?? "",
      csjAndroidCodeId: json['csjAndroidCodeId'] ?? "",
      csjIosCodeId: json['csjIosCodeId'] ?? "",
      versionEnvDesc: json['versionEnvDesc'] ?? "",
    );
  }
}
